//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.member;

import com.aidong.dao.wills.CardTypeCodeDao;
import com.aidong.dao.wills.DicSalesCodeDao;
import com.aidong.dao.wills.GiftCardDao;
import com.aidong.dao.wills.MemberBlackListDao;
import com.aidong.dao.wills.MemberCardDao;
import com.aidong.dao.wills.MemberContractDao;
import com.aidong.dao.wills.MemberEarnestDao;
import com.aidong.dao.wills.MemberInfoDao;
import com.aidong.dao.wills.PayAliDao;
import com.aidong.dao.wills.PayTypeCodeDao;
import com.aidong.dao.wills.PromotionCardTypeDao;
import com.aidong.dao.wills.PromotionDao;
import com.aidong.dao.wills.PtContractDao;
import com.aidong.model.wills.CardTypeCode;
import com.aidong.model.wills.DicSalesCode;
import com.aidong.model.wills.GiftCard;
import com.aidong.model.wills.MemberCard;
import com.aidong.model.wills.MemberContract;
import com.aidong.model.wills.MemberEarnest;
import com.aidong.model.wills.MemberInfo;
import com.aidong.model.wills.PayAli;
import com.aidong.model.wills.PayList;
import com.aidong.model.wills.Promotion;
import com.aidong.model.wills.PromotionCardType;
import com.aidong.model.wills.PssProductCode;
import com.aidong.model.wills.PtContract;
import com.aidong.service.AliPayService;
import com.aidong.service.SmsListService;
import com.aidong.web.controller.BaseController;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

public class PayController extends BaseController {
    @Resource
    protected DicSalesCodeDao dicSalesCodeDao;
    @Resource
    protected MemberInfoDao memberInfoDao;
    @Resource
    protected MemberContractDao memberContractDao;
    @Resource
    protected MemberEarnestDao memberEarnestDao;
    @Resource
    protected MemberCardDao memberCardDao;
    @Resource
    protected CardTypeCodeDao cardTypeCodeDao;
    @Resource
    protected PromotionDao promotionDao;
    @Resource
    protected PromotionCardTypeDao promotionCardTypeDao;
    @Resource
    protected PtContractDao ptContractDao;
    @Resource
    protected SmsListService smsListService;
    @Resource
    protected PayTypeCodeDao payTypeCodeDao;
    @Resource
    protected PayAliDao payAliDao;
    @Resource
    protected AliPayService aliPayService;
    @Resource
    protected MemberBlackListDao memberBlackListDao;
    @Resource
    protected GiftCardDao giftCardDao;

    public PayController() {
    }

    @RequestMapping({"getPay"})
    public ModelAndView getPay(@RequestParam("money") Double money, @RequestParam(value = "sales",required = false) String sales, @RequestParam(value = "giftCard",required = false) String giftCard, @RequestParam(value = "baosteel",required = false) String baosteel) {
        if(!this.chkNull(sales)) {
            DicSalesCode salesCode = this.dicSalesCodeDao.getByCode(sales);
            if(salesCode == null) {
                sales = null;
            }
        }

        return (new ModelAndView("member/pay" + ("1".equals(baosteel)?"_baosteel":""))).addObject("money", money).addObject("payType", this.payTypeCodeDao.getValidList()).addObject("alipay", "1").addObject("sales", sales).addObject("giftCard", giftCard);
    }

    @RequestMapping({"getSales"})
    @ResponseBody
    public String getSales(@RequestParam("code") String code) {
        DicSalesCode sales = this.dicSalesCodeDao.getByCode(code);
        if(sales == null) {
            sales = this.dicSalesCodeDao.getByName(code);
        }

        if(sales == null) {
            return this.getResult(false, "销售员编号错误");
        } else if(sales.getStatus().intValue() != 1) {
            return this.getResult(false, "销售员已离职");
        } else {
            StringBuilder sb = new StringBuilder();
            sb.append("{code:\"").append(sales.getCode()).append("\"").append(",name:\"").append(sales.getChName()).append("\"").append("}");
            return this.getSuccess(sb.toString(), "");
        }
    }

    @RequestMapping({"getCardList"})
    public ModelAndView getCardList() {
        List list = this.memberCardDao.getNotUseList(this.getLoginShopCode());
        List lstp = this.memberCardDao.getNotUseTypeCount(this.getLoginShopCode());
        return (new ModelAndView("member/card")).addObject("list", list).addObject("lstp", lstp);
    }

    @RequestMapping({"getCardNew"})
    @ResponseBody
    public String getCardNew(@RequestParam("cardCode") String cardCode) {
        MemberCard card = this.memberCardDao.getByCardCode(cardCode);
        if(card != null && card.getShopCode().equalsIgnoreCase(this.getLoginShopCode())) {
            if(card.getStatus().intValue() != 1) {
                return this.getResult(false, "卡号已使用,请选择其他卡号");
            } else {
                StringBuilder sb = new StringBuilder();
                sb.append("{cardCode:\"").append(card.getCardCode()).append("\"").append(",memberCode:\"").append(this.nvl(card.getMemberCode())).append("\"").append(",status:").append(card.getStatus()).append("").append("}");
                return this.getSuccess(sb.toString(), "");
            }
        } else {
            return this.getResult(false, "没有这个卡号");
        }
    }

    @RequestMapping({"getGiftCardList"})
    public ModelAndView getGiftCardList() {
        List list = this.giftCardDao.getNotReceiveList(this.getLoginShopCode());
        List lstp = this.giftCardDao.getNotReceiveTypeCount(this.getLoginShopCode());
        return (new ModelAndView("member/giftcard")).addObject("list", list).addObject("lstp", lstp);
    }

    @RequestMapping({"getGiftCardNew"})
    @ResponseBody
    public String getGiftCardNew(@RequestParam("cardCode") String cardCode) {
        GiftCard card = this.giftCardDao.getByCardCode(cardCode);
        if(card != null && card.getShopCode().equalsIgnoreCase(this.getLoginShopCode())) {
            if(card.getStatus().intValue() != 1) {
                return this.getResult(false, "卡号已使用,请选择其他卡号");
            } else if(card.getReportLoss().intValue() == 1) {
                return this.getResult(false, "卡号已挂失,请选择其他卡号");
            } else {
                StringBuilder sb = new StringBuilder();
                sb.append("{cardCode:\"").append(card.getCardCode()).append("\"").append(",cardType:\"").append(this.nvl(card.getCardType())).append("\"").append(",memberCode:\"").append(this.nvl(card.getMemberCode())).append("\"").append(",status:").append(card.getStatus()).append("").append("}");
                return this.getSuccess(sb.toString(), "");
            }
        } else {
            return this.getResult(false, "没有这个卡号");
        }
    }

    @RequestMapping({"getPromotion"})
    @ResponseBody
    public String getPromotion(@RequestParam("id") int id) {
        Promotion promotion = (Promotion)this.promotionDao.getById(Integer.valueOf(id));
        if(promotion == null) {
            return this.getResult(false, "活动编号错误");
        } else {
            List cardList = this.promotionCardTypeDao.getCardTypeList(id);
            List productList = this.promotionDao.getProductList(id, false);
            StringBuilder sb = new StringBuilder();
            sb.append("{id:\"").append(promotion.getPromotionId()).append("\"").append(",name:\"").append(promotion.getChName()).append("\"").append(",cardTypeList:[");
            int sn = 0;

            Iterator i$;
            PromotionCardType product;
            for(i$ = cardList.iterator(); i$.hasNext(); sb.append("{code:\"").append(product.getCardType()).append("\"").append(",name:\"").append(this.cache.getValue("cardType", product.getCardType())).append("\"").append("}")) {
                product = (PromotionCardType)i$.next();
                if(sn++ > 0) {
                    sb.append(",");
                }
            }

            sb.append("],productList:[");
            sn = 0;

            PssProductCode var9;
            for(i$ = productList.iterator(); i$.hasNext(); sb.append("{code:\"").append(var9.getProductCode()).append("\"").append(",name:\"").append(var9.getProductName()).append("\"").append(",price:\"").append(var9.getPrice()).append("\"").append("}")) {
                var9 = (PssProductCode)i$.next();
                if(sn++ > 0) {
                    sb.append(",");
                }
            }

            sb.append("]}");
            return this.getSuccess(sb.toString(), "");
        }
    }

    @RequestMapping({"getEarnestList"})
    public ModelAndView getEarnestList(@RequestParam("type") String type, @RequestParam(value = "memberCode",required = false) String memberCode) {
        List list = null;
        if("2".equals(type) && !this.chkNull(memberCode)) {
            MemberInfo member = this.memberInfoDao.getByMemberCode(memberCode);
            if(member != null) {
                list = this.memberEarnestDao.getNotUseListByName(this.getLoginShopCode(), type, member.getChName());
            }
        } else {
            list = this.memberEarnestDao.getNotUseList(this.getLoginShopCode(), type, memberCode);
        }

        return (new ModelAndView("member/earnest")).addObject("list", list);
    }

    @RequestMapping({"getEarnest"})
    @ResponseBody
    public String getEarnest(@RequestParam("id") int id) {
        MemberEarnest earnest = (MemberEarnest)this.memberEarnestDao.getById(Integer.valueOf(id));
        if(earnest == null) {
            return this.getResult(false, "定金编号错误");
        } else {
            String cardCode = earnest.getCardCode();
            String memberPhoto = null;
            String idCardPhoto = null;
            if(!this.chkNull(earnest.getMemberCode())) {
                MemberInfo sb = this.memberInfoDao.getById(earnest.getMemberCode());
                if(sb != null) {
                    cardCode = sb.getCardCode();
                    memberPhoto = sb.getMemberPhoto();
                    idCardPhoto = sb.getIdCardPhoto();
                }
            }

            StringBuilder sb1 = new StringBuilder();
            sb1.append("{saleId:\"").append(earnest.getSaleId()).append("\"").append(",shopCode:\"").append(earnest.getShopCode()).append("\"").append(",shopName:\"").append(this.cache.getValue("shopName", earnest.getShopCode())).append("\"").append(",saleDate:").append(earnest.getSaleDate().getTime()).append("").append(",overDueDate:").append(earnest.getOverDueDate().getTime()).append("").append(",overDueUse:").append(earnest.getOverDueUse()).append("").append(",payAmount:").append(earnest.getEarnestAmount()).append("").append(",cardType:\"").append(this.nvl(earnest.getCardType())).append("\"").append(",cardTypeName:\"").append(this.nvl(this.cache.getValue("cardType", earnest.getCardType()))).append("\"").append(",cardCode:\"").append(this.nvl(cardCode)).append("\"").append(",memberCode:\"").append(this.nvl(earnest.getMemberCode())).append("\"").append(",memberName:\"").append(earnest.getCustName()).append("\"").append(",gender:\"").append(earnest.getGender()).append("\"").append(",genderName:\"").append(this.cache.getValue("gender", earnest.getGender())).append("\"").append(",idType:\"").append(earnest.getIdType()).append("\"").append(",idTypeName:\"").append(this.cache.getValue("idType", earnest.getIdType())).append("\"").append(",idNumber:\"").append(earnest.getIdNumber()).append("\"").append(",mobile:\"").append(earnest.getMobile()).append("\"").append(",memberPhoto:\"").append(this.nvl(memberPhoto)).append("\"").append(",idCardPhoto:\"").append(this.nvl(idCardPhoto)).append("\"").append("}");
            return this.getSuccess(sb1.toString(), "");
        }
    }

    @RequestMapping({"getMember"})
    @ResponseBody
    public String getMember(@RequestParam("cardCode") String cardCode) {
        MemberInfo member = this.memberInfoDao.getByCardCode(cardCode);
        if(member == null) {
            return this.getResult(false, "会员卡号错误");
        } else if(this.memberBlackListDao.chkExists(member.getIdType(), member.getIdNumber())) {
            return this.getFail(-8, "会员证件号在黑名单中，不能办理");
        } else {
            MemberContract contract = this.memberContractDao.getByMemberCode(member.getMemberCode());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String contractEnd = "";
            if(contract != null) {
                if(contract.getNewEndTime() != null) {
                    contractEnd = sdf.format(contract.getNewEndTime());
                } else if(contract.getEndTime() != null) {
                    contractEnd = sdf.format(contract.getEndTime());
                }
            }

            Date ptEndTime = this.ptContractDao.getMaxEndTimeByMemberCode(member.getMemberCode());
            if(ptEndTime != null && ptEndTime.before(new Date())) {
                ptEndTime = null;
            }

            StringBuilder sb = new StringBuilder();
            sb.append("{code:\"").append(member.getMemberCode()).append("\"").append(",card:\"").append(member.getCardCode()).append("\"").append(",shop:\"").append(member.getShopCode()).append("\"").append(",name:\"").append(member.getChName()).append("\"").append(",gender:\"").append(member.getGender()).append("\"").append(",genderName:\"").append(this.cache.getValue("gender", member.getGender())).append("\"").append(",idType:\"").append(member.getIdType()).append("\"").append(",idTypeName:\"").append(this.cache.getValue("idType", member.getIdType())).append("\"").append(",idNumber:\"").append(member.getIdNumber()).append("\"").append(",mobile:\"").append(member.getMobile()).append("\"").append(",contractEnd:\"").append(contractEnd).append("\"").append(",ptContractEnd:\"").append(ptEndTime == null?"":sdf.format(ptEndTime)).append("\"").append(",memberPhoto:\"").append(this.nvl(member.getMemberPhoto())).append("\"").append(",idCardPhoto:\"").append(this.nvl(member.getIdCardPhoto())).append("\"").append("}");
            return this.getSuccess(sb.toString(), "");
        }
    }

    @RequestMapping({"getContract"})
    @ResponseBody
    public String getContract(@RequestParam("code") String code, @RequestParam(value = "tp",required = false) Integer tp) {
        MemberInfo member = null;
        MemberContract contract;
        if(tp != null && tp.intValue() == 2) {
            member = this.memberInfoDao.getByCardCode(code);
            if(member == null) {
                return this.getResult(false, "会员卡号错误");
            }

            contract = this.memberContractDao.getCurrentByMemberCode(member.getMemberCode());
            if(contract == null) {
                contract = this.memberContractDao.getByMemberCode(member.getMemberCode());
            }

            if(contract == null) {
                return this.getResult(false, "会员无有效合同");
            }
        } else {
            contract = this.memberContractDao.getByContractCode(code);
            if(contract == null) {
                return this.getResult(false, "合同号错误");
            }
        }

        Date beginTime = contract.getBeginTime();
        Date endTime = contract.getEndTime();
        if(beginTime != null && endTime != null && contract.getStatus().intValue() == 1 && contract.getEffectiveDate() == null && !"8".equals(contract.getSaleType())) {
            double leftAmount;
            if(contract.getEndTime().getTime() < System.currentTimeMillis()) {
                leftAmount = 0.0D;
            } else if(contract.getTotalCount().intValue() > 0) {
                leftAmount = (double)Math.round((double)contract.getRestCount().intValue() * contract.getFactPrice().doubleValue() / (double)contract.getTotalCount().intValue());
            } else if(beginTime.getTime() > System.currentTimeMillis()) {
                leftAmount = contract.getFactPrice().doubleValue();
            } else {
                leftAmount = (double)Math.round((double)(endTime.getTime() - System.currentTimeMillis()) * contract.getFactPrice().doubleValue() / (double)(endTime.getTime() - beginTime.getTime()));
            }

            if(leftAmount > contract.getFactPrice().doubleValue()) {
                leftAmount = contract.getFactPrice().doubleValue();
            }

            if(leftAmount <= 0.0D) {
                leftAmount = 0.0D;
            }

            if(member == null) {
                member = this.memberInfoDao.getByMemberCode(contract.getMemberCode());
                if(member == null) {
                    return this.getResult(false, "会员信息错误");
                }
            }

            if(this.memberBlackListDao.chkExists(member.getIdType(), member.getIdNumber())) {
                return this.getFail(-8, "会员证件号在黑名单中，不能办理");
            } else {
                boolean canPreferRenewal = false;
                if("04".equals(contract.getValidUnit()) && contract.getFactPrice().doubleValue() >= 1500.0D) {
                    canPreferRenewal = true;
                }

                CardTypeCode cardType = (CardTypeCode)this.cardTypeCodeDao.getById(contract.getCardType());
                if(cardType == null) {
                    return this.getResult(false, "合同会籍类型错误");
                } else {
                    Date maxEndTime = this.memberContractDao.getMaxEndTimeByMemberCode(member.getMemberCode());
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    StringBuilder sb = new StringBuilder();
                    sb.append("{contractCode:\"").append(contract.getContractCode()).append("\"").append(",shopCode:\"").append(contract.getShopCode()).append("\"").append(",shopName:\"").append(this.cache.getValue("shopName", contract.getShopCode())).append("\"").append(",saleDate:").append(contract.getSaleDate().getTime()).append("").append(",beginTime:").append(beginTime.getTime()).append("").append(",endTime:").append(endTime.getTime()).append("").append(",beginDays:").append((System.currentTimeMillis() - beginTime.getTime()) / 86400000L).append("").append(",factPrice:").append(contract.getFactPrice()).append("").append(",leftAmount:").append(leftAmount).append("").append(",preferRenewal:").append(canPreferRenewal?1:0).append("").append(",cardType:\"").append(contract.getCardType()).append("\"").append(",cardTypeName:\"").append(this.cache.getValue("cardType", contract.getCardType())).append("\"").append(",stopFee:").append(contract.getStopFee()).append("").append(",chgShopFee:").append(contract.getChgShopFee()).append("").append(",mendFee:").append(contract.getMendFee()).append("").append(",changeFee:").append(contract.getChangeFee()).append("").append(",allowUpdate:").append(cardType.getAllowUpdate()).append("").append(",directorCard:").append(cardType.getDirectorCard()).append("").append(",cardCode:\"").append(member.getCardCode()).append("\"").append(",memberCode:\"").append(member.getMemberCode()).append("\"").append(",memberName:\"").append(member.getChName()).append("\"").append(",gender:\"").append(member.getGender()).append("\"").append(",genderName:\"").append(this.cache.getValue("gender", member.getGender())).append("\"").append(",idType:\"").append(member.getIdType()).append("\"").append(",idTypeName:\"").append(this.cache.getValue("idType", member.getIdType())).append("\"").append(",idNumber:\"").append(member.getIdNumber()).append("\"").append(",mobile:\"").append(member.getMobile()).append("\"").append(",memberPhoto:\"").append(this.nvl(member.getMemberPhoto())).append("\"").append(",idCardPhoto:\"").append(this.nvl(member.getIdCardPhoto())).append("\"").append(",contractEnd:\"").append(maxEndTime == null?"":sdf.format(maxEndTime)).append("\"").append("}");
                    return this.getSuccess(sb.toString(), "");
                }
            }
        } else {
            return this.getResult(false, "无效合同");
        }
    }

    @RequestMapping({"getPtContract"})
    @ResponseBody
    public String getPtContract(@RequestParam("code") String code) {
        PtContract contract = this.ptContractDao.getByContractCode(code);
        if(contract == null) {
            return this.getResult(false, "合同号错误");
        } else {
            Date beginTime = contract.getBeginTime();
            Date endTime = contract.getEndTime();
            if(contract.getStatus().intValue() == 1 && contract.getOutTime() == null) {
                MemberInfo member = this.memberInfoDao.getById(contract.getMemberCode());
                if(member == null) {
                    return this.getResult(false, "会员信息错误");
                } else {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    StringBuilder sb = new StringBuilder();
                    sb.append("{contractCode:\"").append(contract.getContractCode()).append("\"").append(",saleId:\"").append(contract.getSaleId()).append("\"").append(",shopCode:\"").append(contract.getShopCode()).append("\"").append(",shopName:\"").append(this.cache.getValue("shopName", contract.getShopCode())).append("\"").append(",saleDate:").append(contract.getSaleDate().getTime()).append("").append(",saleType:\"").append(contract.getSaleType()).append("\"").append(",saleTypeName:\"").append(this.cache.getValue("ptSaleType", contract.getSaleType())).append("\"").append(",beginTime:").append(beginTime.getTime()).append("").append(",endTime:").append(endTime.getTime()).append("").append(",commissionDate:\"").append(contract.getCommissionDate() == null?"":sdf.format(contract.getCommissionDate())).append("\"").append(",factPrice:").append(contract.getFactPrice()).append("").append(",earnestAmount:").append(contract.getEarnestAmount()).append("").append(",payAmount:").append(contract.getPayAmount()).append("").append(",quantity:").append(contract.getQuantity()).append("").append(",leftQuantity:").append(contract.getQuantity().intValue() - contract.getBespeakQuantity().intValue()).append("").append(",ptCode:\"").append(contract.getPtCode()).append("\"").append(",ptCodeName:\"").append(this.cache.getValue("ptItemName", contract.getPtCode())).append("\"").append(",coachCode:\"").append(contract.getCoachCode()).append("\"").append(",coachName:\"").append(this.cache.getValue("ptCoachName", contract.getCoachCode())).append("\"").append(",cardCode:\"").append(member.getCardCode()).append("\"").append(",memberCode:\"").append(member.getMemberCode()).append("\"").append(",memberName:\"").append(member.getChName()).append("\"").append(",salesCode:\"").append(this.nvl(contract.getSalesCode())).append("\"").append(",salesName:\"").append(this.nvl(this.cache.getValue("salesName", contract.getSalesCode()))).append("\"").append(",salesCode2:\"").append(this.nvl(contract.getSalesCode2())).append("\"").append(",salesName2:\"").append(this.nvl(this.cache.getValue("salesName", contract.getSalesCode2()))).append("\"").append("}");
                    return this.getSuccess(sb.toString(), "");
                }
            } else {
                return this.getResult(false, "无效合同");
            }
        }
    }

    protected PayList getPayList(String payls, List<PayList> payList, String saleType, StringBuilder msg) {
        double money = 0.0D;
        String sales1 = null;
        String sales2 = null;
        String[] ss = payls.split("\\|");
        String[] s1 = ss[0].split(",");
        sales1 = s1[0];
        if(s1.length > 1) {
            sales2 = s1[1];
        }

        if(sales1 == null) {
            sales1 = "";
        }

        if(sales2 == null) {
            sales2 = "";
        }

        for(int pay = 1; pay < ss.length; ++pay) {
            s1 = ss[pay].split(",");
            PayList pay1 = new PayList();
            pay1.setPayType(s1[0]);
            pay1.setAmount(Double.valueOf(Double.parseDouble(s1[1])));
            if(s1.length > 2) {
                pay1.setNote(s1[2]);
            }

            pay1.setSalesCode(sales1);
            pay1.setSalesCode2(sales2);
            pay1.setCashier(this.getLoginUserCode());
            pay1.setShopCode(this.getLoginShopCode());
            pay1.setSaleType(saleType);
            pay1.setSaleDate(new Date());
            pay1.setCreateUser(this.getLoginUserCode());
            pay1.setCreateTime(new Date());
            pay1.setUpdateTime(new Date());
            money += pay1.getAmount().doubleValue();
            payList.add(pay1);
            if("S011".equalsIgnoreCase(pay1.getPayType())) {
                if(this.chkNull(pay1.getNote())) {
                    msg.append("请填写支付宝支付条码");
                    return null;
                }

                PayAli payAli = this.payAliDao.getByBarCode(pay1.getNote());
                if(payAli == null || !payAli.getShopCode().equalsIgnoreCase(this.getLoginShopCode())) {
                    msg.append("支付宝支付条码错误");
                    return null;
                }

                if(payAli.getStatus().intValue() == 0) {
                    msg.append("支付宝条码未完成支付");
                    return null;
                }

                if(payAli.getStatus().intValue() == 2) {
                    msg.append("支付宝条码已完成支付");
                    return null;
                }

                if(payAli.getStatus().intValue() == 3 || payAli.getStatus().intValue() == 4) {
                    msg.append("支付宝条码已取消支付");
                    return null;
                }

                if(payAli.getStatus().intValue() != 1) {
                    msg.append("支付宝条码不能使用");
                    return null;
                }
            }
        }

        PayList var14 = new PayList();
        var14.setAmount(Double.valueOf(money));
        var14.setSalesCode(sales1);
        var14.setSalesCode2(sales2);
        return var14;
    }

    @RequestMapping({"_getAliPay"})
    @ResponseBody
    public String _getAliPay(@RequestParam("barCode") String barCode, @RequestParam("money") Double money) {
        PayAli payAli = this.payAliDao.getByBarCode(barCode);
        if(payAli != null) {
            if(!payAli.getShopCode().equalsIgnoreCase(this.getLoginShopCode())) {
                return this.getResult(false, "非本店支付条码");
            } else {
                this.queryAliPay(payAli);
                return payAli.getStatus().intValue() == 2?this.getResult(false, "该条码已完成支付"):(payAli.getStatus().intValue() != 3 && payAli.getStatus().intValue() != 4?this.getSuccess(this.getPayAliJson(payAli), "支付条码已存在" + (payAli.getStatus().intValue() == 0?",请完成付款":"")):this.getResult(false, "该条码已取消支付"));
            }
        } else if(this.chkNullZ(money)) {
            return this.getResult(false, "付款金额错误");
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
            String shopCode = this.getLoginShopCode();
            String tradeNo = shopCode + sdf.format(new Date());
            StringBuilder alipayNo = new StringBuilder();
            StringBuilder msg = new StringBuilder();
            if(this.aliPayService.createPay(barCode, tradeNo, money.doubleValue(), shopCode, alipayNo, msg)) {
                payAli = new PayAli();
                payAli.setShopCode(shopCode);
                payAli.setBarCode(barCode);
                payAli.setAmount(money);
                payAli.setTradeNo(tradeNo);
                payAli.setAlipayNo(alipayNo.toString());
                payAli.setStatus(Integer.valueOf(0));
                payAli.setCreateUser(this.getLoginUserCode());
                payAli.setCreateTime(new Date());
                payAli.setUpdateTime(new Date());

                try {
                    this.payAliDao.add(payAli);
                    this.addUserLog("新增支付宝付款", "编号:" + payAli.getAutoId() + ",条码:" + payAli.getBarCode());
                    return this.getSuccess(this.getPayAliJson(payAli), "提交成功,请完成付款");
                } catch (Exception var10) {
                    this.log.error("add payali", var10);
                    return this.getResult(false, "保存支付宝付款发生错误");
                }
            } else {
                return this.getResult(false, msg.toString());
            }
        }
    }

    @RequestMapping({"getAliPay"})
    @ResponseBody
    public String getAliPay(@RequestParam("barCode") String barCode) {
        PayAli payAli = this.payAliDao.getByBarCode(barCode);
        if(payAli != null) {
            if(!payAli.getShopCode().equalsIgnoreCase(this.getLoginShopCode())) {
                return this.getResult(false, "非本店支付条码");
            } else {
                this.queryAliPay(payAli);
                return payAli.getStatus().intValue() == 2?this.getResult(false, "该条码已完成支付"):(payAli.getStatus().intValue() != 3 && payAli.getStatus().intValue() != 4?this.getSuccess(this.getPayAliJson(payAli), payAli.getStatus().intValue() == 0?"请完成付款":"已付款"):this.getResult(false, "该条码已取消支付"));
            }
        } else {
            return this.getResult(false, "没有这个支付条码");
        }
    }

    private void queryAliPay(PayAli payAli) {
        if(payAli.getStatus().intValue() == 0) {
            StringBuilder msg = new StringBuilder();
            HashMap rep = new HashMap();
            int ret = this.aliPayService.queryPay(payAli.getTradeNo(), rep, msg);
            if(ret > 0) {
                payAli.setStatus(Integer.valueOf(ret));
                payAli.setPayTime(new Date());
                payAli.setAlipayNo((String)rep.get("trade_no"));
                payAli.setPayUser((String)rep.get("buyer_logon_id"));
                this.payAliDao.updatePayStatus(payAli);
            }
        }

    }

    private String getPayAliJson(PayAli payAli) {
        return "{barCode:\"" + payAli.getBarCode() + "\",amount:" + payAli.getAmount() + ",status:" + payAli.getStatus() + "}";
    }
}
